package info.empathymobile.forecastmethods;

public class WeightedMovingAverage implements ForecastMethod {

	public static final String NAME = "Weighted Moving Average";
	public static final int VERSION = 3;

	@Override
	public String getName() {
		return NAME;
	}
	@Override
	public int getVersion() {
		return VERSION;
	}
	
	@Override
	public int[] doForecasting(int[] timeSeries, int horizon) {
		//Variables
		int t = timeSeries.length-1-horizon;
		int n = 20; //mean window
		
		if(n > timeSeries.length-horizon){
			n = timeSeries.length-horizon;
		}
		
		for (int h = 1; h <= horizon; h++) {
			int meanSum = 0;
			int totalWeight = 0;
			for (int i = 0; i < n; i++) {
				int weight = n-i;
				meanSum += timeSeries[t-i]*weight;
				totalWeight += weight;
			}
			timeSeries[t+1] = meanSum/totalWeight;
			t++;
		}
		return timeSeries;
	}
}